// index.js
// 获取应用实例
const app = getApp();


Page({
  data: {
    list:[],
    introduce:'',
    showBag:false,
    showzb:false,
    text_zb:'装备',
    showIntroduce:false
  },
  
  ccyl:function(){
    wx.navigateTo({
      url: '/pages/ccyl/ccyl',
    })

  },
  cfp:function(){
    wx.navigateTo({
      url: '/pages/cfp/cfp',
    })

  },
  zhp:function(){
    wx.navigateTo({
      url: '/pages/zhp/zhp',
    })

  },
  gotonvwu:function(){
    wx.navigateTo({
      url: '/pages/nvwu/nvwu',
    })

  },
  
  home:function(){
    wx.navigateTo({
      url: '/pages/home/home',
    })

  },
  chengjiao:function(){
    wx.navigateTo({
      url: '/pages/chengjiao/chengjiao',
    })

  },
  beibao:function(){
    var showBag = this.data.showBag;
    this.setData({
      showBag:!showBag
    });
    var that = this;
    wx.request({
      url: 'http://localhost:8080/beibao',
      data:{

      },
      header:{
        "content-type":"application/json"
      },
      success:function(res){
        console.log(res.data);
        that.setData({
          list:res.data
        })
      }
    })


  },
  showIntroduce:function(e){
    var showIntroduce = this.data.showIntroduce;
    var showzb = this.data.showzb;
    this.setData({
      showIntroduce:!showIntroduce
    });
    var index = e.currentTarget.dataset.index;
    console.log(index);
    var list = this.data.list;
    var introduce = list[index].introduce;
    if(list[index].name=='屠龙宝刀'||list[index].name=='玄武盔甲'||list[index].name=='弯刀'){
      this.setData({
        showzb:!showzb
      });
    }
    this.setData({
      introduce:introduce
    })

  },
  zhuangbei:function(e){
    var list = this.data.list;
    var index = e.currentTarget.dataset.index2;
    console.log(index);
    var that = this;
    wx.request({
      url: 'http://localhost:8080/zhuangbei',
      data:{
        bag:list[index]
      },
      header:{
        "content-type":"application/json"
      },
      success:function(res){
        app.globalData.player = res.data;
        console.log(app.globalData.player);
        that.setData({
          text_zb:'已装备'
        });
      }
    })



  },
  

  // 事件处理函数
  bindViewTap() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad() {
    var that = this;
    wx.request({
      url: 'http://localhost:8080/beibao',
      data:{

      },
      header:{
        "content-type":"application/json"
      },
      success:function(res){
        console.log(res.data);
        that.setData({
          list:res.data
        })
      }
    });
    
  },
  
})
